home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / Common / include / didcfgview.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  26.4 KB  |  867 lines

  1. //-----------------------------------------------------------------------------
  2. // File: didcfgview.h
  3. //
  4. // Desc: Header file for DIDCfgView, a class that encapsulates a view of a
  5. //       DirectInput device.  The DIDCfgView class exists to make it easier 
  6. //       to make custom interfaces to view or configure action mappings for 
  7. //       input devices(instead of using IDirectInput8::ConfigureDevices).
  8. //
  9. //       To use the DIDCfgView class, you initialize it for a particular
  10. //       DirectInput device.  You then set up state information for how the
  11. //       image should be drawn: colors, fonts, and details for callouts(the
  12. //       lines drawn from each axis/button to a label).  Finally, you can 
  13. //       call RenderView, passing in a bitmap or HDC for DIDCfgView to draw
  14. //       the image to.
  15. //
  16. //       DIDCfgView is the only class in this file that you need to understand 
  17. //       or interface to.  The other classes shown here are only used to 
  18. //       implement the DIDCfgView class.
  19. //
  20. //
  21. // Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
  22. //-----------------------------------------------------------------------------
  23.  
  24. #ifndef __DIDCV_H__
  25. #define __DIDCV_H__
  26.  
  27.  
  28.  
  29.  
  30. #include <windows.h>
  31. #include <dinput.h>
  32.  
  33.  
  34.  
  35.  
  36. // invalid id, used for unique, signed identifiers
  37. #define DIDCV_INVALID_ID                            -1
  38.  
  39. // flags for callout states
  40. #define DIDCV_DRAWCALLOUT                           0x1
  41. #define DIDCV_DRAWOVERLAY                           0x2
  42. #define DIDCV_DRAWHIGHLIGHT                         0x4
  43. #define DIDCV_DRAWEMPTYCALLOUT                      0x8
  44. #define DIDCV_DRAWFULLNAME                          0x10
  45.  
  46. // all flags set
  47. #define DIDCV_ALL_CALLOUT_STATE_SET                 0xFFFFFFFF
  48.  
  49. // default dimensions
  50. #define DIDCV_MAX_IMAGE_WIDTH                       512
  51. #define DIDCV_MAX_IMAGE_HEIGHT                      512
  52. #define DIDCV_CUSTOM_VIEW_WIDTH                     400
  53. #define DIDCV_CUSTOM_VIEW_HEIGHT                    300
  54.  
  55. // DidcvCreateFont attribute flags
  56. #define DIDCV_FONT_BOLD                             0x1
  57. #define DIDCV_FONT_ITALIC                           0x2
  58. #define DIDCV_FONT_UNDERLINE                        0x4
  59. #define DIDCV_FONT_STRIKEOUT                        0x8
  60.  
  61. // default font point width
  62. #define DIDCV_DEFAULT_FONT_SIZE                     90
  63.  
  64. // default size of callout array in DidcvCalloutManager
  65. #define DIDCV_DEFAULT_CALLOUT_MANAGER_ARRAY_SIZE    0
  66.  
  67. // default size of callout array in DidcvCalloutSet
  68. #define DIDCV_DEFAULT_CALLOUT_SET_ARRAY_SIZE        8
  69.  
  70.  
  71.  
  72.  
  73. // forward declarations
  74. class DidcvViewManager;
  75. class DidcvCalloutManager;
  76. class DidcvBitmap;
  77. class DidcvCallout;
  78. class DidcvCalloutSet;
  79. struct DIDCfgViewInfo;
  80. struct DidcvCalloutData;
  81. struct DidcvCalloutState;
  82. struct DidcvActionMap;
  83. struct DidcvCustomViewInfo;
  84.  
  85.  
  86.  
  87.  
  88. //-----------------------------------------------------------------------------
  89. // Name: class DIDCfgView
  90. // Desc: main interface for retrieving and rendering device configuration views
  91. //
  92. //       Init() - initializes the object for a particular DirectInputDevice
  93. //       SetActionFormat() - sets the action mapping for the device
  94. //       SetCalloutState() - specifies state for a given callout
  95. //       SetAllCalloutState() - sets the state for all callouts
  96. //       GetObjectIDByLocation() - gets object id at location of current view
  97. //       SetCurrentView() - sets the current view to be rendered
  98. //       RebuildViews() - collapses or expand the views for this device
  99. //       RenderView() - renders device configuration view with image,
  100. //                       callout information, action mapping.
  101. //-----------------------------------------------------------------------------
  102. class DIDCfgView
  103. {
  104. public:
  105.     DIDCfgView();
  106.     ~DIDCfgView();
  107.  
  108. public:
  109.     // main device configuration view interface
  110.     HRESULT Init( LPDIRECTINPUTDEVICE8 pDevice );
  111.     HRESULT SetActionFormat( LPDIACTIONFORMAT pDiaf );
  112.     HRESULT SetCalloutState( DWORD dwFlags, DWORD dwObjID );
  113.     HRESULT SetAllCalloutState( DWORD dwFlags );
  114.     HRESULT GetObjectIDByLocation( LPDWORD pdwObjID, LPPOINT pPt );
  115.     HRESULT SetCurrentView( INT nView );
  116.     HRESULT RebuildViews( BOOL bCompact );
  117.     HRESULT RenderView( HBITMAP hBitmap, BOOL bIsDib );
  118.     HRESULT RenderView( HDC hdc );
  119.  
  120.     // rendering options
  121.     HRESULT SetViewOrigin( const POINT* pPtOrg, POINT* pPtOldOrg );
  122.     HRESULT CalcCenterOrgForCurrentView( const SIZE* pImgSize, POINT* pPtOrg, BOOL bSetOrigin = FALSE );
  123.     VOID    SetDefaultText( const TCHAR* pctszDefaultText, DWORD length );
  124.     VOID    SetColors( COLORREF crFore, COLORREF crBack, COLORREF crHighlight, COLORREF crHighlightLine );
  125.     VOID    GetColors( COLORREF* pCrFore, COLORREF* pCrBack, COLORREF* pCrHighlight, COLORREF* pCrHighlightLine );
  126.     HRESULT SetFont( const TCHAR*  pctszFontName, DWORD dwAttributes );
  127.     HFONT   GetFont();
  128.  
  129.     // information access functios
  130.     HRESULT GetInfo( DIDCfgViewInfo* pCfgViewInfo );
  131.     HRESULT GetCurrentView( LPINT lpnView );
  132.     HRESULT GetCalloutState( LPDWORD lpdwFlags, DWORD dwObjID );
  133.  
  134. protected:
  135.     // protected helper functions
  136.     VOID    CleanUp();
  137.     HRESULT InitAlloc();
  138.     HRESULT InitImageInfoRetrieve( LPDIRECTINPUTDEVICE8 pDevice );
  139.     HRESULT InitImageInfoProcess();
  140.     VOID    CalcSizes( const DIDEVICEIMAGEINFO* prgImageInfoArray, DWORD dwNumElements, const LPDWORD pNumViews, LPDWORD pNumCallouts, LPDWORD pNumDistinctObjID );
  141.     HRESULT RenderView( HDC hdc, VOID* pBits, INT width, INT height );
  142.  
  143.     HRESULT InitCustomViews( LPDIRECTINPUTDEVICE8 pDevice, BOOL bUseInternal = FALSE );
  144.     HRESULT BuildCustomViews();
  145.     VOID    RenderFullname( HDC hdc, const TCHAR* pctszFullname, const RECT* pRect );
  146.     BOOL    CopyActionMap( LPDIACTIONFORMAT pDiaf );
  147.  
  148. protected:
  149.     // data structures for managing views and callouts
  150.     DidcvViewManager* m_lpViewManager;
  151.     DidcvCalloutManager* m_lpCalloutManager;
  152.  
  153.     // keeps track of whether this has been initialized
  154.     BOOL m_bIsInit;
  155.     // the index of the next view to render
  156.     INT m_nView;
  157.     // pointer to the DIDEVICEIMAGEINFOHEADER
  158.     LPDIDEVICEIMAGEINFOHEADER m_lpDidImgHeader;
  159.     // custom device view data
  160.     DidcvCustomViewInfo* m_lpCustomViewInfo;
  161.  
  162.     // device reference
  163.     LPDIRECTINPUTDEVICE8 m_lpDIDevice;
  164.     // action mapping copy
  165.     LPDIACTIONFORMAT m_lpDiaf;
  166.     // can this view be collapsed
  167.     BOOL m_bCanBeCollapsed;
  168.     // is this view compacted
  169.     BOOL m_bIsCollapsed;
  170.  
  171.     // rendering options
  172.     COLORREF m_crFore;
  173.     COLORREF m_crBack;
  174.     COLORREF m_crHighlight;
  175.     COLORREF m_crHighlightLine;
  176.     POINT    m_ptOrigin;
  177.     HFONT    m_hFont;
  178.     TCHAR m_tszDefaultText [MAX_PATH];
  179. };
  180.  
  181.  
  182.  
  183.  
  184. //-----------------------------------------------------------------------------
  185. // Name: struct DIDCfgViewInfo
  186. // Desc: struct containing current information about DIDCfgView states
  187. //-----------------------------------------------------------------------------
  188. struct DIDCfgViewInfo
  189. {
  190.     BOOL  bIsInit;              // is the CfgView object initialized
  191.     INT   iCurrentViewID;       // the ID of the current view
  192.     INT   iNumTotalViews;       // total number of views
  193.     DWORD dwNumUniqueCallouts;  // number of unique
  194.     BOOL  bCanBeCollapsed;      // can views for this CfgView object be compacted
  195.     BOOL  bIsCollapsed;         // is the CfgView currently using collapsed views
  196.  
  197.  
  198.     DIDCfgViewInfo()
  199.         : bIsInit( FALSE ),
  200.           iCurrentViewID( DIDCV_INVALID_ID ),
  201.           iNumTotalViews( 0 ),
  202.           dwNumUniqueCallouts( 0 ),
  203.           bCanBeCollapsed( FALSE ),
  204.           bIsCollapsed( FALSE )
  205.     { }
  206. };
  207.  
  208.  
  209.  
  210.  
  211. //-----------------------------------------------------------------------------
  212. // Name: struct DidcvCustomViewInfo
  213. // Desc: object containing information about custom views
  214. //-----------------------------------------------------------------------------
  215. struct DidcvCustomViewInfo
  216. {
  217.     DWORD dwType;               // type of the operation(count or save)
  218.     DWORD dwCount;              // the total count of items
  219.     DWORD dwSize;               // number of items actually in array
  220.     LPDIDEVICEOBJECTINSTANCE* rgObjData;   // array of control info
  221.  
  222.     DidcvCustomViewInfo()
  223.         : dwType( 0 ),
  224.           dwCount( 0 ),
  225.           dwSize( 0 ),
  226.           rgObjData( NULL )
  227.     { }
  228.  
  229.     ~DidcvCustomViewInfo() { CleanUp(); }
  230.     
  231.     VOID CleanUp();
  232. };
  233.  
  234.  
  235.  
  236.  
  237. //-----------------------------------------------------------------------------
  238. // Name: class DidcvView
  239. // Desc: data structure for representing one view of a device
  240. //-----------------------------------------------------------------------------
  241. class DidcvView
  242. {
  243. public:
  244.     virtual ~DidcvView() { };
  245.  
  246.     // DidcvView interface
  247.     void SetOffset( INT nOffset );
  248.     void SetID( INT nID );
  249.     INT  GetOffset() const;
  250.     INT  GetID() const;
  251.  
  252.     // rendering
  253.     virtual BOOL GetViewSize( SIZE* pSize ) const = 0;
  254.     virtual void Render( HDC hdc, VOID* pBits, INT width, INT height, const POINT* pPtOrigin ) = 0;
  255.  
  256. protected:
  257.     // constructor
  258.     DidcvView();
  259.     // the original offset in the array returned by DirectInputDevice8::GetImage
  260.     INT m_nOffset;
  261.     // the internally assigned unique identifier
  262.     INT m_nID;
  263. };
  264.  
  265.  
  266.  
  267.  
  268. //-----------------------------------------------------------------------------
  269. // Name: class DidcvBitmapView
  270. // Desc: subclass of DidcvView that renders a bitmap
  271. //-----------------------------------------------------------------------------
  272. class DidcvBitmapView : public DidcvView
  273. {
  274. public:
  275.     ~DidcvBitmapView();
  276.  
  277.     // interface
  278.     virtual BOOL GetViewSize( SIZE* pSize ) const;
  279.     virtual void Render( HDC hdc, VOID* pBits, INT width, INT height, const POINT* pPtOrigin );
  280.  
  281. public:
  282.     // function to instantiate a DidcvBitmapView
  283.     static DidcvBitmapView* Create( LPCTSTR ptszImagePath, DWORD dwFlags );
  284.  
  285. private:
  286.     // constructor
  287.     DidcvBitmapView();
  288.  
  289. protected:
  290.     // bitmap of the view
  291.     DidcvBitmap* m_lpBitmap;
  292. };
  293.  
  294.  
  295.  
  296.  
  297. //-----------------------------------------------------------------------------
  298. // Name: class DidcvCustomView
  299. // Desc: subclass of DidcvView that renders a view from custom data
  300. //-----------------------------------------------------------------------------
  301. class DidcvCustomView : public DidcvView
  302. {
  303. public:
  304.     ~DidcvCustomView() { }
  305.  
  306.     // interface
  307.     virtual BOOL GetViewSize( SIZE* pSize ) const;
  308.     virtual void Render( HDC hdc, VOID* pBits, INT width, INT height, const POINT* pPtOrigin );
  309.  
  310. public:
  311.     // static function to instantiate a DidcvCustomView
  312.     static DidcvCustomView* Create( const DidcvCustomViewInfo* pInfo, DWORD dwStartIndex, DWORD* pFinishIndex );
  313.     static BOOL CalcImageInfo( DWORD index, LPRECT rcOverlay, LPDWORD pNumPoints, LPPOINT rgptCalloutLine, LPRECT rcCalloutRect );
  314.     static DWORD CalcNumViews( DWORD dwCount );
  315.  
  316. private:
  317.     // constructor
  318.     DidcvCustomView( const DidcvCustomViewInfo* pInfo, DWORD dwStartIndex, DWORD dwEndIndex );
  319.  
  320. protected:
  321.     // returns coordinates for a given index
  322.     void CalcCoordinates( DWORD dwIndex, LPRECT lpRect );
  323.  
  324.     // custom data from which to render the view
  325.     const DidcvCustomViewInfo* m_lpCustomViewInfoRef;
  326.     DWORD m_dwStartIndex;
  327.     DWORD m_dwEndIndex;
  328. };
  329.  
  330.  
  331.  
  332.  
  333. //-----------------------------------------------------------------------------
  334. // Name: class DidcvViewManager
  335. // Desc: stores and manages all the views for particular device
  336. //-----------------------------------------------------------------------------
  337. class DidcvViewManager
  338. {
  339. public:
  340.     DidcvViewManager();
  341.     ~DidcvViewManager();
  342.  
  343.     // interface
  344.     BOOL SetCapacity( UINT uCapacity, BOOL bDeleteContent = TRUE );
  345.     BOOL AddImage( DidcvView* pView, INT nOffset = DIDCV_INVALID_ID );
  346.     DidcvView* GetImage( INT nID );
  347.     DidcvView* GetImageByOffset( INT nOffset );
  348.     UINT GetNumViews() const;
  349.     void CleanUp();
  350.  
  351. protected:
  352.     // table holding references to views, indexed by the internal unique identifier
  353.     DidcvView ** m_ppViewTable;
  354.     UINT m_capacity;
  355.     UINT m_size;
  356. };
  357.  
  358.  
  359.  
  360.  
  361. //-----------------------------------------------------------------------------
  362. // Name: class DidcvCallout
  363. // Desc: data structure for representing one callout on a particular view
  364. //       A callout is the line drawn from each axis/button to a label
  365. //-----------------------------------------------------------------------------
  366. class DidcvCallout
  367. {
  368. public:
  369.     ~DidcvCallout();
  370.  
  371.     // accessor functions to information retrieved from DirectInput
  372.     DWORD GetObjID() const;
  373.     const RECT & GetOverlayRect() const;
  374.     const RECT & GetCalloutRect() const;
  375.     const POINT* GetCalloutLine( DWORD* lpNumPts ) const;
  376.     DWORD GetTextAlign() const;
  377.     DWORD GetOverlayOffset() const;
  378.  
  379.     // accessor functions to internal data
  380.     void  SetAssociatedViewID( INT nViewRef );
  381.     INT   GetAssociatedViewID() const;
  382.     void  SetDataRef( const DidcvCalloutData* lpData );
  383.     const DidcvCalloutData* GetDataRef() const;
  384.  
  385.     // hit test for a given point
  386.     DWORD HitTest( LPPOINT lpPt ) const;
  387.  
  388.     // draw the overlay
  389.     DWORD DrawOverlay( HDC hDC, VOID* lpBits, INT width, INT height, const POINT* pptOrigin );
  390.  
  391. public:
  392.     // static functions to instantiate a callout object
  393.     static DidcvCallout* Create( LPDIDEVICEIMAGEINFO devImgInfo );
  394.  
  395. private:
  396.     // private constructor
  397.     DidcvCallout();
  398.  
  399. protected:
  400.     // copy of device information
  401.     DIDEVICEIMAGEINFO m_devImgInfo;
  402.     // the view that this particular callout is associated with
  403.     INT m_nViewRef;
  404.     // pointer to callout state/data
  405.     const DidcvCalloutData* m_lpDataRef;
  406.     // the bitmap of the overlay
  407.     DidcvBitmap* m_lpOverlayBitmap;
  408. };
  409.  
  410.  
  411.  
  412.  
  413. // default array size
  414. #define GW_ARRAY_DEFAULT_SIZE       4
  415.  
  416. //-----------------------------------------------------------------------------
  417. // Name: class GwArray
  418. // Desc: templated c-style array class for PRIMITIVE data types only
  419. //-----------------------------------------------------------------------------
  420. template <class Item> 
  421. class GwArray
  422. {
  423. public:
  424.     // constructors
  425.     GwArray() { this->Alloc( GW_ARRAY_DEFAULT_SIZE ); m_size = 0; }
  426.     GwArray( UINT initCap ) { this->Alloc( initCap ); m_size = 0; }
  427.     ~GwArray() { this->DeAlloc(); m_size = 0; }
  428.  
  429. public:
  430.     void SetSize( UINT newCap )
  431.     {
  432.         if( newCap == m_capacity )
  433.             return;
  434.  
  435.         m_size =( newCap < m_size ? newCap : m_size );
  436.  
  437.         UINT old_cap = m_capacity;
  438.         UINT numoverlap =( newCap > m_capacity ? m_capacity : newCap );
  439.  
  440.         Item* oldList = m_list;
  441.         this->Alloc( newCap );
  442.  
  443.         if( oldList )
  444.         {
  445.             memcpy( m_list, oldList, sizeof( Item )* numoverlap );
  446.  
  447.             // free( oldList );
  448.             delete [] oldList;
  449.         }
  450.     }
  451.  
  452.     Item & operator[]( UINT index )
  453.     {
  454.         if( index >= m_capacity )
  455.             assert( index >= 0 && index < m_capacity );
  456.  
  457.         return m_list[index];
  458.     }
  459.  
  460.     const Item & operator[]( UINT index ) const
  461.     {
  462.         if( index >= m_capacity )
  463.             assert( index >= 0 && index < m_capacity );
  464.  
  465.         return m_list[index];
  466.     }
  467.  
  468.     void PushBack( const Item & item )
  469.     {
  470.         if( m_capacity == 0 )
  471.             SetSize( 2 );
  472.         else if( m_size >= m_capacity )
  473.             SetSize( m_capacity* 2 );
  474.  
  475.         m_list[m_size] = item;
  476.         m_size++;
  477.     }
  478.  
  479.     void Resize( UINT newCap ) { SetSize( newCap ); }
  480.     void PopBack()        { if( m_size ) m_size--; }
  481.     void Clear()          { m_size = 0; }
  482.     void Trim()           { Resize( m_size ); }
  483.     UINT Capacity() const { return m_capacity; }
  484.     UINT Size() const     { return m_size; }
  485.  
  486. protected:
  487.     inline void Alloc( UINT cap )
  488.     {
  489.         if( cap == 0 )
  490.             m_list = NULL;
  491.         else
  492.         {
  493.             m_list = new Item[cap];
  494.             assert( m_list );
  495.             memset( m_list, 0, sizeof( Item )* cap );
  496.         }
  497.  
  498.         m_capacity = cap;
  499.     }
  500.  
  501.     inline void DeAlloc()
  502.     {
  503.         if( m_list != NULL )
  504.         {
  505.             //free( m_list );
  506.             delete [] m_list;
  507.             m_list = NULL;
  508.         }
  509.  
  510.         m_capacity = 0;
  511.     }
  512.  
  513. protected:
  514.     // array
  515.     Item* m_list;
  516.     // number of entries the array can hold
  517.     UINT m_capacity;
  518.     // number of entries added using PushBack() minus # removed using PopBack()
  519.     UINT m_size;
  520. };
  521.  
  522.  
  523.  
  524.  
  525. //-----------------------------------------------------------------------------
  526. // Name: class DidcvCalloutApplicant
  527. // Desc: abstract base class for processing DidcvCallout
  528. //-----------------------------------------------------------------------------
  529. class DidcvCalloutApplicant
  530. {
  531. public:
  532.     virtual ~DidcvCalloutApplicant() { }
  533.     virtual BOOL Apply( DidcvCallout* pCallout ) = 0;
  534. };
  535.  
  536.  
  537.  
  538.  
  539. //-----------------------------------------------------------------------------
  540. // Name: class DidcvCalloutSet
  541. // Desc: a group of DidcvCallout references
  542. //       A callout is the line drawn from each axis/button to a label
  543. //-----------------------------------------------------------------------------
  544. class DidcvCalloutSet
  545. {
  546. public:
  547.     DidcvCalloutSet();
  548.     ~DidcvCalloutSet();
  549.  
  550. public:
  551.     BOOL  AddCallout( DidcvCallout* pCallout );
  552.     void  Apply( DidcvCalloutApplicant* pCalloutApp );
  553.     void  SetIdentifier( DWORD dwID );
  554.     DWORD GetIdentifier() const;
  555.     void  SetData( void* pData );
  556.     void* GetData() const;
  557.  
  558.     const GwArray <DidcvCallout*> & GetInternalArrayRef() const;
  559.     void  TrimArrays();  
  560.  
  561. protected:
  562.     void CleanUp();
  563.  
  564. protected:
  565.     GwArray <DidcvCallout*> m_calloutList;
  566.     DWORD m_dwSetID;
  567.     void* m_lpData;
  568. };
  569.  
  570.  
  571.  
  572.  
  573. //-----------------------------------------------------------------------------
  574. // Name: class DidcvCalloutManager
  575. // Desc: data structure for storing and managing callouts
  576. //       A callout is the line drawn from each axis/button to a label
  577. //-----------------------------------------------------------------------------
  578. class DidcvCalloutManager
  579. {
  580. public:
  581.     DidcvCalloutManager();
  582.     ~DidcvCalloutManager();
  583.  
  584.     // main interface
  585.     BOOL  AddCallout( DidcvCallout* pCallout, INT nView );
  586.     BOOL  SetCalloutState( const DidcvCalloutState* pCalloutState, DWORD dwObjID );
  587.     BOOL  SetAllCalloutState( const DidcvCalloutState* pCalloutState );
  588.     BOOL  SetActionMap( const LPDIACTION pAction, DWORD dwObjID );
  589.     void  ClearAllActionMaps();
  590.  
  591.     // information
  592.     DWORD GetObjectIDByLocation( const LPPOINT pPt, INT nView );
  593.     BOOL  GetCalloutState( DidcvCalloutState* pCalloutState, DWORD dwObjID );
  594.     BOOL  GetActionMap( DidcvActionMap* pActionMap, DWORD dwObjID );
  595.     const DidcvCalloutSet* GetCalloutSetByView( INT nView ) const;
  596.     const DidcvCalloutSet* GetCalloutSetByObjID( DWORD dwObjID ) const;
  597.     const DidcvCalloutData* GetCalloutDataRef( DWORD dwObjID ) const;
  598.     UINT  GetNumUniqueCallouts() const;
  599.  
  600.     BOOL  EnumObjects( LPDIRECTINPUTDEVICE8 pDevice, LPDIENUMDEVICEOBJECTSCALLBACK pCallback, LPVOID pvRef, DWORD dwMapOnly );
  601.     BOOL  CalcCanBeCollapsed();
  602.  
  603.     // allocation
  604.     BOOL  SetCapacity( DWORD dwNumCallouts, DWORD dwNumUniqueObjID, DWORD dwNumViews, BOOL bDeleteContent = TRUE );
  605.     void  TrimArrays();
  606.     void  CleanUp();
  607.  
  608. protected:
  609.     // helper functions
  610.     DidcvCalloutSet*  Find( const GwArray <DidcvCalloutSet*> & array, DWORD dwIdentifier ) const;
  611.     DidcvCalloutData* GetCalloutData( DWORD dwObjID ) const;
  612.  
  613. protected:
  614.     // list of all callouts added
  615.     GwArray <DidcvCallout*> m_calloutList;
  616.     // list of callout sets, one for each unique callout id
  617.     GwArray <DidcvCalloutSet*> m_calloutSetListByObjID;
  618.     // list of callout sets, one for each view
  619.     GwArray <DidcvCalloutSet*> m_calloutSetListByView;
  620. };
  621.  
  622.  
  623.  
  624.  
  625. //-----------------------------------------------------------------------------
  626. // Name: struct DidcvCalloutData
  627. // Desc: data structure holding references to callout data components
  628. //-----------------------------------------------------------------------------
  629. struct DidcvCalloutData
  630. {
  631.     DidcvCalloutState* lpState;    // callout state info
  632.     DidcvActionMap* lpActionMap;   // action mapped this callout
  633.  
  634.     DidcvCalloutData( DidcvCalloutState* s, DidcvActionMap* a )
  635.         : lpState( s ), lpActionMap( a )
  636.     { }
  637. };
  638.  
  639.  
  640.  
  641.  
  642. //-----------------------------------------------------------------------------
  643. // Name: struct DidcvCalloutState
  644. // Desc: state information for a callout
  645. //-----------------------------------------------------------------------------
  646. struct DidcvCalloutState
  647. {
  648.     // whether to draw
  649.     BOOL bDrawCallout;
  650.     BOOL bDrawOverlay;
  651.     BOOL bDrawHighlight;
  652.     BOOL bDrawEmptyCallout;
  653.     BOOL bDrawFullname;
  654.  
  655.     // specifies which state is valid
  656.     DWORD dwFlags;
  657.  
  658.     // --- member functions ---
  659.     DidcvCalloutState( DWORD f = 0, BOOL c = FALSE, BOOL o = FALSE, 
  660.         BOOL h = FALSE, BOOL e = FALSE, BOOL d = FALSE )
  661.         : dwFlags( f ), bDrawCallout( c ), bDrawOverlay( o ), bDrawHighlight( h ), 
  662.           bDrawEmptyCallout( e ), bDrawFullname( d )
  663.     { }
  664.  
  665.     void SmartSet( const DidcvCalloutState* other );
  666.     void Copy( const DidcvCalloutState* other ) { *this = *other; }
  667.     DWORD MakeFlag() const;
  668.     void SetFlag( DWORD dwExtFlags );
  669. };
  670.  
  671.  
  672.  
  673.  
  674. //-----------------------------------------------------------------------------
  675. // Name: struct DidcvActionMap
  676. // Desc: action mapping information for a callout
  677. //-----------------------------------------------------------------------------
  678. struct DidcvActionMap
  679. {
  680.     DIACTION dia;
  681.  
  682.     DidcvActionMap() { ZeroMemory( &dia, sizeof( DIACTION ) ); }
  683.     void Copy( const DidcvActionMap* other ) { this->dia = other->dia; }
  684.  
  685.     LPCSTR GetActionName() const { return dia.lptszActionName; }
  686. };
  687.  
  688.  
  689.  
  690.  
  691. // utility functions
  692. void  DidcvPolyLineArrow( HDC hDC, const POINT* rgpt, INT nPoints, BOOL bDoShadow = FALSE );
  693. HFONT DidcvCreateFont( HDC hdc, const TCHAR* szFaceName, int iDeciPtHeight, int iDeciPtWidth, int iAttributes, BOOL fLogRes);
  694.  
  695.  
  696.  
  697.  
  698. //-----------------------------------------------------------------------------
  699. // Name: struct rgref
  700. // Desc: templated lightweight c-style array
  701. //-----------------------------------------------------------------------------
  702. template <class T>
  703. struct rgref {
  704.     rgref( T* p ) : pt( p ) {}
  705.  
  706.     T & operator []( int i ) { return pt[i]; }
  707.     const T & operator []( int i ) const { return pt[i]; }
  708.  
  709. private:
  710.     T *pt;
  711. };
  712.  
  713.  
  714.  
  715.  
  716. //-----------------------------------------------------------------------------
  717. // Name: struct SPOINT
  718. // Desc: used by line drawing routine
  719. //-----------------------------------------------------------------------------
  720. struct SPOINT {
  721.     SPOINT()
  722. #define SPOINT_INITIALIZERS \
  723.         p( u.p ), \
  724.         s( u.s ), \
  725.         a((( int* )( void* ) u.a ) ), \
  726.         x( u.p.x ), \
  727.         y( u.p.y ), \
  728.         cx( u.s.cx ), \
  729.         cy( u.s.cy )
  730.         : SPOINT_INITIALIZERS
  731.         { x = y = 0; }
  732.  
  733.     SPOINT( int, POINT *r ) 
  734.         : p( *r ),
  735.           s( *(( SIZE* )( void* ) r ) ),
  736.           a((( int* )( void* ) r ) ),
  737.           x( r->x ),
  738.           y( r->y ),
  739.           cx( r->x ),
  740.           cy( r->y )
  741.     { }
  742.  
  743.     SPOINT( const SPOINT & sp ) 
  744.         : SPOINT_INITIALIZERS
  745.     { p = sp.p; }
  746.  
  747.     SPOINT( int b, int c ) 
  748.         : SPOINT_INITIALIZERS
  749.     { x = b; y = c; }
  750.  
  751.     SPOINT( const POINT &point )
  752.         : SPOINT_INITIALIZERS
  753.     { p = point; }
  754.  
  755.     SPOINT( const SIZE &size )
  756.         : SPOINT_INITIALIZERS
  757.     { s = size; }
  758.  
  759. #undef SPOINT_INITIALIZERS
  760.  
  761.     SPOINT operator =( const SPOINT &sp ) { p = sp.p; return *this; }
  762.     SPOINT operator =( const POINT &_p ) { p = _p; return *this; }
  763.     SPOINT operator =( const SIZE &_s ) { s = _s; return *this; }
  764.  
  765.     operator POINT() const { return p; }
  766.     operator SIZE() const { return s; }
  767.  
  768.     long &x, &y, &cx, &cy;
  769.     POINT &p;
  770.     SIZE &s;
  771.     rgref<int> a;
  772.  
  773. private:
  774.     union {
  775.         POINT p;
  776.         SIZE s;
  777.         int a[2];
  778.     } u;
  779. };
  780.  
  781.  
  782.  
  783.  
  784. //-----------------------------------------------------------------------------
  785. // Name: class DidcvBitmap
  786. // Desc: object containing a bitmap
  787. //-----------------------------------------------------------------------------
  788. class DidcvBitmap
  789. {
  790. public:
  791.     ~DidcvBitmap();
  792.  
  793.     // drawing interface
  794.     BOOL Draw( HDC hDC, INT xStart, INT yStart);
  795.     BOOL Blend( HDC hDC, INT xStart, INT yStart );
  796.     BOOL Blend( VOID* lpBits, INT xStart, INT yStart, INT width, INT height );
  797.  
  798.     // information
  799.     BOOL GetSize( SIZE* lpSize ) const;
  800.     HBITMAP GetHandle();
  801.     LPVOID GetBits();
  802.  
  803. public:
  804.     // static function for instantiating a DidcvBitmap
  805.     static DidcvBitmap* Create( LPCTSTR tszFilename );
  806.     static DidcvBitmap* Create( INT width, INT height );
  807.  
  808. private:
  809.     // private constructor
  810.     DidcvBitmap();
  811.  
  812. protected:
  813.     // helper functions
  814.     void CleanUp();
  815.     void FigureSize();
  816.  
  817.     static DidcvBitmap* CreateViaD3dx( LPCTSTR tszFilename );
  818.     static DidcvBitmap* CreateViaLoadImage( HINSTANCE hinst, LPCTSTR tszName, 
  819.         UINT uType, int cx, int cy, UINT fuLoad );
  820.  
  821. protected:
  822.     // GDI handle to bitmap
  823.     HBITMAP m_hbitmap;
  824.     VOID* m_lpBits;
  825.     SIZE m_size;
  826. };
  827.  
  828.  
  829.  
  830.  
  831. // alpha blending information
  832. #define DIDCV_ALPHABLEND_DLL_NAME   TEXT( "MSIMG32.DLL" )
  833. #define DIDCV_ALPHABLEND_PROC_NAME  TEXT( "AlphaBlend" )
  834.  
  835. #if( WINVER >= 0x400 )
  836.   typedef WINGDIAPI BOOL( WINAPI* DIDCV_ALPHABLEND )( HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION );
  837. #else
  838.   typedef DIDCV_ALPHABLEND DWORD
  839. #endif
  840.  
  841. //-----------------------------------------------------------------------------
  842. // Name: class DidcvAlphaBlend
  843. // Desc: utility class for alpha blending
  844. //-----------------------------------------------------------------------------
  845. class DidcvAlphaBlend
  846. {
  847. public:
  848.     // reference counting interface
  849.     static BOOL AddClient();
  850.     static BOOL ReleaseClient();
  851.  
  852.     // functions to perform blending
  853.     static BOOL Blend( HDC hDC, INT xStart, INT yStart, INT width, INT height, HBITMAP hbitmap, const SIZE* lpSize );
  854.     static BOOL Blend( VOID* lpDestBits, INT xStart, INT yStart, INT destWidth, INT destHeight, VOID* lpSrcBits, INT srcWidth, INT srcHeight );
  855.  
  856. protected:
  857.     static DIDCV_ALPHABLEND s_alphaBlendProc;
  858.     static HMODULE s_hDll;
  859.     static DWORD s_dwNumClients;
  860.  
  861. };
  862.  
  863.  
  864.  
  865.  
  866. #endif // #ifndef __DIDCV_H__
  867.